import Request from '../default'
import obj from '../api'

function getImages () {
  return Request({
    url: obj.banner,
    method: 'get'
  })
}

function getTypes () {
  return Request({
    url: obj.types,
    method: 'get'
  })
}

async function getTypesOnly () {
  const { data: res } = await Request({
    url: obj.types,
    method: 'get'
  })
  res.map(type => {
    delete type.products
    return type
  })
  return res
}

// 获取商品
async function getPro (typename) {
  const { data: res } = await Request({
    url: obj.types,
    method: 'get'
  })
  if (typename === '全部') {
    var arr = []
    res.forEach(type => {
      arr = arr.concat(type.products)
    })
    return arr
  } else {
    // 根据typename筛选数据
    var products = res.find(type => type.name === typename).products
    return products
  }
}

export {
  getImages,
  getTypes,
  getTypesOnly,
  getPro
}
